<?php
/**
* * Model Class
* 
* @author Guillermo Landín
* @link 
* 
* 
*/ 

class Gallerymodel extends Model {

    function __construct()
    {
        parent::Model();
        
        $this->CI =& get_instance(); 
    }

    //returns the list of active images as a simple array
    function get_list($fields="*")
    {
        $this->db->select($fields)
                ->from('gallery')
                ->where('Active_Gallery', 1);  

        $query = $this->db->get();
        $result = $query->result_array();
        
        //$result = array();
        //foreach($result as $img) {
        //    $return[] = $img['image'];
        //}
           
        return $result;
    }
    

/***********************************
*   Backoffice functions
***********************************/

    function admin_get_list($fields='*')
    {
        $this->db->select($fields)
                ->from('gallery');  

        $query = $this->db->get();                       
        return $query->result_array();
    }  
    public function admin_get_item($id=FALSE, $fields='*')
    {
        $this->db->select($fields)
                ->from('gallery')       
                ->where('id_Gallery', $id);  
        
        $query = $this->db->get();
        return $query->row_array();
    }  
    public function admin_update($id=FALSE, $data=array())
    {
        $this->db->where('id_Gallery', $id)
                ->update('gallery', $data); 
    }                      
    public function admin_insert($data=array())
    {
        $data["Active_Gallery"] = 1;
        $this->db->insert('gallery', $data); 
        return $this->db->insert_id();
    }  
    public function admin_delete($id=FALSE)
    {
        $this->db->where('id_Gallery', $id);
        $this->db->delete('gallery'); 
    } 


}
